package com.dede.getmusic.module.home

import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.che300.kotlin.extand.color
import com.che300.kotlin.extand.toHtml
import com.dede.getmusic.R
import com.dede.getmusic.data.SearchInfo

/**
 * @author hsh
 * @date 2017/10/12 14:49.
 * @doc
 */
class SearchListAdapter(layoutId: Int, data: List<SearchInfo.SongsBean>) :
        BaseQuickAdapter<SearchInfo.SongsBean, BaseViewHolder>(layoutId, data) {

    private var mKey = ""

    fun setKey(key: String) {
        this.mKey = key
    }

    override fun convert(helper: BaseViewHolder, item: SearchInfo.SongsBean) {
        val title = helper.getView<TextView>(R.id.tv_title)
        val subTitle = helper.getView<TextView>(R.id.tv_sub)
        val key = mKey.color(helper.itemView.context, R.color.colorAccent)
        var text = item.name.replace(mKey, key)
        title.text = text.toHtml()

        text = item.artistsName + " - " + item.album.name
        text = text.replace(mKey, key)
        subTitle.text = text.toHtml()

        helper.addOnClickListener(R.id.iv_download)
    }

}